<?php
/**
 * Created by PhpStorm.
 * User: zhangfulai
 * Date: 2018/10/10
 * Time: 上午9:51
 */

namespace app\api\model;
use think\Model;
use think\Db;

class Feedback extends Model{

    protected function initialize()
    {
        //需要调用`Model`的`initialize`方法
        parent::initialize();
        //TODO:自定义的初始化
    }

    // 自动转换
    protected function getCtimeAttr($vlue){
        return date("Y-m-d H:i:s",$vlue);
    }
    protected function getUtimeAttr($vlue){
        return date("Y-m-d H:i:s",$vlue);
    }
    /**
     * Notes: 查找反馈列表信息
     * Create Date: 2018/10/2
     * Create Time: 15:34
     * Create by :lijie
     * $w : 条件
     */
    public function feedbackList($pageNum,$listNum,$w,$type){
        if($type == 1){
            $reslt["list"] = $this
                ->alias("a")
                ->field("a.*,c.nickName")
                ->join("__USER__ c","a.mix_id = c.u_id")
                ->where($w)
                ->page($pageNum,$listNum)
                ->order("a.ctime desc")
                ->select();
            $reslt["total"] = $this
                ->alias("a")
                ->where($w)
                ->count("a.id");
            return $reslt;
        }else if($type == 3){
            $reslt["list"] = $this
                ->alias("a")
                ->field("a.*,c.name")
                ->join("__CASH__ c","a.mix_id = c.a_id")
                ->where($w)
                ->page($pageNum,$listNum)
                ->order("a.ctime desc")
                ->select();
            $reslt["total"] = Db::name("feedback")
                ->alias("a")
                ->where($w)
                ->count("a.id");
            return $reslt;
        }
    }
    public function updateFeedback($w,$c){
        $result = $this
            ->where($w)
            ->update($c);
        return $result;
    }
}